package com.caigou.service.impl;

import com.caigou.service.GenerateYctService;
import com.caigou.util.QRCodeUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Slf4j
@Service
public class GenerateYctServiceImpl implements GenerateYctService {

    @Resource
    private QRCodeUtils qrCodeUtils;

    @Value("${form.catalog.mobile_url}")
    private String mobileUrl;

    @Value("${form.catalog.logo_path_yct}")
    private String logoPathYct;

    @Value("${form.catalog.destPath")
    private String destPath;

    @Override
    public String generateYctCode(Integer courseId)  {
        if(courseId==0||courseId==-1){
            log.error("参数有误,courseId={}", courseId);
            return null;
        }
//        https://testmform.caigou2003.com/#/course?courseId=123
        //seminarId 该成 courseId
        String yct = mobileUrl+"course?courseId="+courseId;

        try{
            String code = qrCodeUtils.encode(yct,logoPathYct,destPath,"yct-Code-"+courseId,true);
            log.info("易采通app中研修班id={}的二维码地址={}", courseId, code);
            return code;
        }catch (Exception e){
            log.error(e.getMessage(),e);
            return null;
        }
    }

    @Override
    public String generateYktHomeCodeInYct() {
        String yktHome = mobileUrl+"course";
        try{
            String code = qrCodeUtils.encode(yktHome,logoPathYct,destPath,"ykt-Home-In-Yct",true);
            log.info("易采通app中易考通首页二维码地址：{}", code);
            return code;
        }catch(Exception e){
            log.error(e.getMessage(), e);
            return null;
        }
    }
}